home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 44 / PC Actual CD 44.iso / Linux / Cygwin / full.exe / Disk1 / data1.cab / Tools / H-i586-cygwin32 / i586-cygwin32 / include / sys / reent.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-04  |  5.9 KB  |  207 lines

  1. /* This header file provides the reentrancy.  */
  2.  
  3. /* WARNING: All identifiers here must begin with an underscore.  This file is
  4.    included by stdio.h and others and we therefore must only use identifiers
  5.    in the namespace allotted to us.  */
  6.  
  7. #ifndef _SYS_REENT_H_
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define _SYS_REENT_H_
  12.  
  13. #include <_ansi.h>
  14.  
  15. struct _glue 
  16. {
  17.   struct _glue *_next;
  18.   int _niobs;
  19.   struct __sFILE *_iobs;
  20. };
  21.  
  22. struct _Bigint 
  23. {
  24.   struct _Bigint *_next;
  25.   int _k, _maxwds, _sign, _wds;
  26.   unsigned long _x[1];
  27. };
  28.  
  29. /*
  30.  * atexit() support
  31.  */
  32.  
  33. #define    _ATEXIT_SIZE 32    /* must be at least 32 to guarantee ANSI conformance */
  34.  
  35. struct _atexit {
  36.     struct    _atexit *_next;            /* next in list */
  37.     int    _ind;                /* next index in this table */
  38.     void    (*_fns[_ATEXIT_SIZE])(void);    /* the table itself */
  39. };
  40.  
  41. /*
  42.  * Stdio buffers.
  43.  *
  44.  * This and __sFILE are defined here because we need them for struct _reent,
  45.  * but we don't want stdio.h included when stdlib.h is.
  46.  */
  47.  
  48. struct __sbuf {
  49.     unsigned char *_base;
  50.     int    _size;
  51. };
  52.  
  53. /*
  54.  * We need fpos_t for the following, but it doesn't have a leading "_",
  55.  * so we use _fpos_t instead.
  56.  */
  57.  
  58. typedef long _fpos_t;        /* XXX must match off_t in <sys/types.h> */
  59.                 /* (and must be `long' for now) */
  60.  
  61. /*
  62.  * Stdio state variables.
  63.  *
  64.  * The following always hold:
  65.  *
  66.  *    if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
  67.  *        _lbfsize is -_bf._size, else _lbfsize is 0
  68.  *    if _flags&__SRD, _w is 0
  69.  *    if _flags&__SWR, _r is 0
  70.  *
  71.  * This ensures that the getc and putc macros (or inline functions) never
  72.  * try to write or read from a file that is in `read' or `write' mode.
  73.  * (Moreover, they can, and do, automatically switch from read mode to
  74.  * write mode, and back, on "r+" and "w+" files.)
  75.  *
  76.  * _lbfsize is used only to make the inline line-buffered output stream
  77.  * code as compact as possible.
  78.  *
  79.  * _ub, _up, and _ur are used when ungetc() pushes back more characters
  80.  * than fit in the current _bf, or when ungetc() pushes back a character
  81.  * that does not match the previous one in _bf.  When this happens,
  82.  * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
  83.  * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
  84.  */
  85.  
  86. struct __sFILE {
  87.   unsigned char *_p;    /* current position in (some) buffer */
  88.   int    _r;        /* read space left for getc() */
  89.   int    _w;        /* write space left for putc() */
  90.   short    _flags;        /* flags, below; this FILE is free if 0 */
  91.   short    _file;        /* fileno, if Unix descriptor, else -1 */
  92.   struct __sbuf _bf;    /* the buffer (at least 1 byte, if !NULL) */
  93.   int    _lbfsize;    /* 0 or -_bf._size, for inline putc */
  94.  
  95.   /* operations */
  96.   _PTR    _cookie;    /* cookie passed to io functions */
  97.  
  98.   int    _EXFUN((*_read),(_PTR _cookie, char *_buf, int _n));
  99.   int    _EXFUN((*_write),(_PTR _cookie, const char *_buf, int _n));
  100.   _fpos_t _EXFUN((*_seek),(_PTR _cookie, _fpos_t _offset, int _whence));
  101.   int    _EXFUN((*_close),(_PTR _cookie));
  102.  
  103.   /* separate buffer for long sequences of ungetc() */
  104.   struct __sbuf _ub;    /* ungetc buffer */
  105.   unsigned char *_up;    /* saved _p when _p is doing ungetc data */
  106.   int    _ur;        /* saved _r when _r is counting ungetc data */
  107.  
  108.   /* tricks to meet minimum requirements even when malloc() fails */
  109.   unsigned char _ubuf[3];    /* guarantee an ungetc() buffer */
  110.   unsigned char _nbuf[1];    /* guarantee a getc() buffer */
  111.  
  112.   /* separate buffer for fgetline() when line crosses buffer boundary */
  113.   struct __sbuf _lb;    /* buffer for fgetline() */
  114.  
  115.   /* Unix stdio files get aligned to block boundaries on fseek() */
  116.   int    _blksize;    /* stat.st_blksize (may be != _bf._size) */
  117.   int    _offset;    /* current lseek offset */
  118.  
  119.   struct _reent *_data;
  120. };
  121.  
  122. /*
  123.  * struct _reent
  124.  *
  125.  * This structure contains *all* globals needed by the library.
  126.  * It's raison d'etre is to facilitate threads by making all library routines
  127.  * reentrant.  IE: All state information is contained here.
  128.  */
  129.  
  130. struct _reent
  131. {
  132.   /* local copy of errno */
  133.   int _errno;
  134.  
  135.   /* FILE is a big struct and may change over time.  To try to achieve binary
  136.      compatibility with future versions, put stdin,stdout,stderr here.
  137.      These are pointers into member __sf defined below.  */
  138.   struct __sFILE *_stdin, *_stdout, *_stderr;
  139.  
  140.   int  _inc;            /* used by tmpnam */
  141.   char _emergency[25];
  142.  
  143.   int _current_category;    /* used by setlocale */
  144.   _CONST char *_current_locale;
  145.  
  146.   int __sdidinit;        /* 1 means stdio has been init'd */
  147.  
  148.   void _EXFUN((*__cleanup),(struct _reent *));
  149.  
  150.   /* used by mprec routines */
  151.   struct _Bigint *_result;
  152.   int _result_k;
  153.   struct _Bigint *_p5s;
  154.   struct _Bigint **_freelist;
  155.  
  156.   /* used by some fp conversion routines */
  157.   int _cvtlen;            /* should be size_t */
  158.   char *_cvtbuf;
  159.  
  160.   /* Two next two fields were once used by malloc.  They are no longer
  161.      used.  I'm leaving them here for now in case there really is a
  162.      binary compatibility issue.  */
  163. #define _N_LISTS 30
  164.   unsigned char * _nextf[_N_LISTS];
  165.   unsigned int _nmalloc[_N_LISTS];
  166.  
  167.   /* atexit stuff */
  168.   struct _atexit *_atexit;    /* points to head of LIFO stack */
  169.   struct _atexit _atexit0;    /* one guaranteed table, required by ANSI */
  170.  
  171.   /* signal info */
  172.   void (**(_sig_func))(void);
  173.  
  174.   /* These are here last so that __sFILE can grow without changing the offsets
  175.      of the above members (on the off chance that future binary compatibility
  176.      would be broken otherwise).  */
  177.   struct _glue __sglue;            /* root of glue chain */
  178.   struct __sFILE __sf[3];        /* first three file descriptors */
  179. };
  180.  
  181. #define _REENT_INIT(var) \
  182.   { 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C" }
  183.  
  184. /*
  185.  * All references to struct _reent are via this pointer.
  186.  * Internally, newlib routines that need to reference it should use _REENT.
  187.  */
  188.  
  189. #ifndef __ATTRIBUTE_IMPURE_PTR__
  190. #define __ATTRIBUTE_IMPURE_PTR__
  191. #endif
  192.  
  193. extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
  194.  
  195. void _reclaim_reent _PARAMS ((struct _reent *));
  196.  
  197. /* #define _REENT_ONLY define this to get only reentrant routines */
  198.  
  199. #ifndef _REENT_ONLY
  200. #define _REENT _impure_ptr
  201. #endif
  202.  
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif /* _SYS_REENT_H_ */
  207.